package com.kakarote.examine.constant;

import cn.hutool.core.collection.ListUtil;
import com.kakarote.core.common.enums.ExamineLabelEnum;
import com.kakarote.core.common.enums.SystemCodeEnum;
import com.kakarote.core.exception.CrmException;

import java.util.Arrays;
import java.util.Objects;

/**
 * 审批label枚举 1 合同 2 回款 3发票 4薪资 5 采购审核 6采购退货审核 7销售审核 8 销售退货审核 9付款单审核10 回款单审核11盘点审核12调拨审核13客户团队成员申请
 */
public enum ExamineEnum {
    CRM_CONTRACT(1, 6, "合同"),
    CRM_RECEIVABLES(2, 7, "回款"),
    CRM_INVOICE(3, 18, "发票"),
    CRM_CUSTOMER_TEAM_MEMBER(13, 0, "客户团队成员申请"),

    ;

    private ExamineEnum(Integer type, Integer relType, String remark) {
        this.type = type;
        this.remark = remark;
    }

    private Integer type;

    /**
     * 引用其他模块的类型
     */
    private Integer relType;
    private String remark;

    public Integer getType() {
        return type;
    }

    public String getRemark() {
        return remark;
    }

    public Integer getRelType() {
        return relType;
    }

    public static ExamineEnum valueOf(Integer type) {
        for (ExamineEnum examineEnum : values()) {
            if (examineEnum.getType().equals(type)) {
                return examineEnum;
            }
        }
        throw new CrmException(SystemCodeEnum.SYSTEM_NO_VALID);
    }

    public static ExamineModuleTypeEnum parseModule(Integer label) {
        int two = 2;
        int three = 3;
        int four = 4;
        int five = 5;
        int six = 6;
        int seven = 7;
        int eight = 8;
        int nine = 9;
        int oneZero = 10;
        int oneOne = 11;
        int oneTwo = 12;
        int oneThree = 13;
        int twoZero = 20;
        int thirty = 30;
        if (Arrays.asList(1, two, three, twoZero, oneThree).contains(label)) {
            return ExamineModuleTypeEnum.Crm;
        }
        if (ExamineLabelEnum.getHrmCode().contains(label)) {
            return ExamineModuleTypeEnum.Hrm;
        }
        if (Arrays.asList(five, six, seven, eight, nine, oneZero, oneOne, oneTwo).contains(label)) {
            return ExamineModuleTypeEnum.Jxc;
        }
        if (Arrays.asList(thirty).contains(label)) {
            return ExamineModuleTypeEnum.Scrm;
        }
        if (Objects.equals(0, label)) {
            return ExamineModuleTypeEnum.Oa;
        }
        throw new CrmException(SystemCodeEnum.SYSTEM_NO_VALID);
    }
}
